<?php

if (!defined("PHPUnit_MAIN_METHOD")) {
    define("PHPUnit_MAIN_METHOD", "SeleniumSystemTest::main");
}

require_once "PHPUnit2/Framework/TestCase.php";
require_once "PHPUnit2/Framework/TestSuite.php";

include_once "Testing/Selenium.php";

/**
 * System Tests
 */
class SeleniumSystemTest extends PHPUnit_Framework_TestCase {

	var $module_obj = null;
	var $selenium = null;
	
	public static function main()
	{
		require_once "PHPUnit2/TextUI/TestRunner.php";
		$suite  = new PHPUnit_Framework_TestSuite("SeleniumSystemTest");
		$result = PHPUnit_TextUI_TestRunner::run($suite);
	}


	protected function setUp()
	{
		if (!class_exists('Testing_Selenium')) 
		{
			print("Selenium tests won't run because you haven't installed/included the module class\n\n");
			print("Run the following PEAR command to install: pear install Testing_Selenium-0.3.0\n\n");
		}
//		print_r($this->module_obj);//TMP
	}

	protected function tearDown()
	{
	}

	/*************** Selenium tests ****************/

	/**
	 * Open the Intranet site, go to /preferences/calendar and check
	 * that the heading is there
	 * 
	 * Assumes that:
	 * a) The Selenium server is running locally
	 * b) You have auto-login set up for the Intranet on IE
	 **/
	function test_view_prefs_calendar()
	{
		$browser = "*firefox";
		$url = "/working-here/meeting-rooms/"; 
		$this->selenium = new Testing_Selenium($browser, "http://intranetdev");
		$this->selenium->start();			    
		$this->selenium->open($url);
		$this->selenium->waitForPageToLoad(2000);		
		$body_text = $this->selenium->getBodyText();
		$this->assertRegExp("/Bookings for/", $body_text);
		$this->selenium->stop();			    
	}
	
/*
    public function test_google()
    {
        $this->selenium = new Testing_Selenium("*firefox", "http://www.google.co.uk/");
        $this->selenium->start();
        $this->selenium->open("/");
        $this->selenium->type("q", "hello world");
        $this->selenium->click("btnG");
        $this->selenium->waitForPageToLoad(1000);
        $this->assertRegExp("/Google Search/", $this->selenium->getTitle());
        $this->selenium->stop();
    }
*/	
	/*************** END Selenium tests ****************/
	
}

if (PHPUnit_MAIN_METHOD == "SeleniumSystemTest::main") {
    SeleniumSystemTest::main();
}
?>
